//
//  ActonMenu.swift
//  swifttest1
//
//  Created by kologe on 2024/9/19.
//

import SwiftUI

struct MessageView: View {
    @State var message:String=""
    @State var placeholder:String="请输入信息"
    @State var remoteHost:String = ""
    @Binding var isShow:Bool
    @State var confirmBtnName:String = "确定"
    @State var cancelBtnName:String = "取消"
    var body: some View {
        VStack{
            Text(placeholder)
            TextEditor(text: $message)
                .padding()
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .disabled(true)
              
            HStack{
               
                Button {
                    isShow = false
                } label: {
                    Label(cancelBtnName, systemImage: "")
                        .foregroundColor(.white)
                        .padding(EdgeInsets(top: 4, leading: 4, bottom: 4, trailing: 4))
                        .background(
                            RoundedRectangle(cornerRadius: 10)
                                .foregroundColor(.blue)
                        )
                        .compositingGroup()
                        .shadow(radius: 5,x:0,y:3)
                        .contentShape(Rectangle())
                }
                .nomalStyle()
                Button {
                    sendMessage()
                } label: {
                    Label(confirmBtnName, systemImage: "")
                        .foregroundColor(.white)
                        .padding(EdgeInsets(top: 4, leading: 4, bottom: 4, trailing: 4))
                        .background(
                            RoundedRectangle(cornerRadius: 10)
                                .foregroundColor(.blue)
                        )
                        .compositingGroup()
                        .shadow(radius: 5,x:0,y:3)
                        .contentShape(Rectangle())
                }
                .nomalStyle()
            }
            
            
            
        }.frame(width: 300,height: 200,alignment: .center)
    }
    func sendMessage(){
        TCPClientManager.shared.sendStringMsg(ip: remoteHost, str: message)
        isShow = false
    }
}



#Preview {
    MessageView( isShow: .constant(false))
}
